<template>
  <div class="oe-push-exam" v-loading="loading">
    <top-tip v-if="!stepMode && batchTitle" :batchTitle="batchTitle" :examTitle="examTitle" :title="title"></top-tip>
    <div class="oe-push-container">
      <div class="oe-push-tab" v-if="!IsCanAdd">
        <a-radio-group v-if="isHasBK" v-model="typeExam" @change="Changetype" button-style="solid">
          <a-radio-button :value="0">正式卷</a-radio-button>
          <a-radio-button :value="1">补考卷</a-radio-button>
        </a-radio-group>
      </div>
      <div class="oe-push-title">
        当前发布试卷：
        <a-select
          v-model="examvalue"
          style="width: 200px"
          @change="handleChange"
          :disabled="!isOnlyLook"
        >
          <a-select-option
            v-for="(item, index) in typelist"
            :value="item.Id"
            :index="index"
            :key="item.Id"
          >{{ item.Name }}</a-select-option>
        </a-select>
        <!-- <a-button type="primary" class="o-ques-name" @click="getQuestionNames()">题型名称设置</a-button> -->
        <a-dropdown placement="bottomLeft" class="o-ques-name">
          <a-button type="primary">
            题型名称设置
            <a-icon type="down" />
          </a-button>
          <a-menu slot="overlay">
            <a-menu-item>
              <a @click="getQuestionNames()">> 按题型设置</a>
            </a-menu-item>
            <a-menu-item>
              <a @click="getWorkQuestion()">> 按题目设置</a>
            </a-menu-item>
          </a-menu>
        </a-dropdown>
        <!-- <span class="oe-set-item__select">
          <a-checkbox
            value="IsAllowMark"
            v-model="IsAllowMark"
            :disabled="!isOnlyLook"
          >若该试卷含有填空题（客观），系统自动批阅后，允许批阅教师再次批阅</a-checkbox>
        </span> -->
      </div>
      <div class="oe-push-title">
        <span class="iconfont icon-canyu"></span>
        <span class="oe-push-title__text">设置参与方式</span>
      </div>
      <div class="oe-push-method">
        <div class="oe-method-left">
          <div class="oe-method-left__title">
            <span class="oe-title-circle"></span>
            登录方式
            <a-tooltip placement="bottom" class="oe-push-top__title">
              <template slot="title">
                <span class="oe-title-info">1.账号+密码登录</span>
                <span class="oe-title-content">考生使用自己的账号和密码登录参加考试</span>
                <span class="oe-title-info">2.账号+密码+口令登录</span>
                <span class="oe-title-content">
                  考生使用账号、密码和教师发布的口令登录考试
                  <br />初始口令为默认口令，学生登录后，若再次登录 口令会发生改变。
                </span>
              </template>
              <i class="iconfont icon-wenti"></i>
            </a-tooltip>
          </div>
          <div class="oe-method-radio">
            <a-radio-group
              @change="onLoginMethod(loginMethod)"
              v-model="loginMethod"
              :disabled="!isOnlyLook"
            >
              <a-radio :value="1">帐号+密码登录</a-radio>
              <a-radio :value="2" v-if="isOnline">账号+密码+口令登录</a-radio>
            </a-radio-group>
            <div v-if="radiovalue == 2" class="oe-method-input">
              <a-input v-model="examLogin" id="copylogin" />
              <span class="oe-copy-link" @click="getCode">更新</span>
              <span
                ref="copylg"
                class="oe-copy-link"
                @mouseover.once="copyLoginAction"
                data-clipboard-target="#copylogin"
                @click.stop="copyLoginAction"
              >复制</span>
            </div>
          </div>
        </div>
        <div class="oe-method-right">
          <div class="oe-method-left__title">
            <span class="oe-title-circle"></span>
            登录时间
            <span class="iconfont icon-wenti o-exam-tips">归档前该选项支持随时修改（注：归档后将不可修改）</span>
          </div>
          <div class="oe-method-time">
            <a-form-model
              ref="ruleForm"
              class="oe-method-form"
              :model="ruleForm"
              :rules="rules"
              layout="inline"
            >
              <div class="a-form-model-content">
                <a-form-model-item label="提前登录时长：" prop="beforeLogin">
                  <a-input v-model="ruleForm.beforeLogin" :min="1" type="number" />
                </a-form-model-item>
                <div class="oe-method-label">考试开始之前，考生可提前多少分钟登录考试</div>
              </div>
              <div class="a-form-model-content">
                <a-form-model-item label="延迟登录时长： " prop="delayLogin">
                  <a-input-number v-model="ruleForm.delayLogin" :min="1" />
                </a-form-model-item>
                <div class="oe-method-label">考试在开始之后，允许考生登录考试</div>
              </div>
              <div class="a-form-model-content">
                <a-form-model-item label="提前交卷时长：" prop="commit">
                  <a-input-number v-model="ruleForm.commit" :min="1" />
                </a-form-model-item>
                <div class="oe-method-label">考试在开始多少分钟后，允许考生交卷</div>
              </div>
            </a-form-model>
          </div>
        </div>
      </div>
      <div class="oe-push-title">
        <span class="iconfont icon-fabu-bold"></span>
        <span class="oe-push-title__text">设置发布方式</span>
      </div>
      <div class="pe-push-method" v-if="isOnline || this.typeExam == 1">
        <!-- <div class="oe-method-left__title">
          <span class="oe-title-circle"></span>
          考试时间
        </div>-->

        <div class="oe-push-left__time" v-if="isOnline" style="width: 1200px;">
          <div class="oe-method-left__title">
            <span class="oe-title-circle"></span>
            考试时间
            <!-- <span class="iconfont icon-dui" v-if="isOnline">该考试为线上考试，学生的考试时间默认为最小的时间</span>

            <i @click="addtimes" v-if="isOnlyLook && IsCanAdd" class="iconfont icon-plus-circle"></i> -->
          </div>
          <template v-for="(examtime, index) in moretime">
            <div :key="index" class="oe-other-set__item">
              <span class="oe-let-time__title">
                <span class="oe-let-time__red">*</span>
                时间：
              </span>
              <a-date-picker
                :disabled="!isOnlyLook"
                :ref="'startTime_' + index"
                :disabled-date="disabledNormalStartDate"
                :show-time="{ defaultValue: $moment('00:00:00', 'HH:mm:ss') }"
                format="YYYY-MM-DD HH:mm"
                v-model="examtime.starttime"
                placeholder="请选择时间"
                @change="changetime"
                @ok="changeOk"
                @openChange="handleStartNormalOpenChange($event, examtime)"
              />
              <span class="oe-let-time__split">--</span>
              <a-date-picker
                :disabled="!isOnlyLook"
                :ref="'endTime_' + index"
                :disabled-date="disabledNormalEndDate"
                :show-time="{ defaultValue: $moment('00:00:00', 'HH:mm:ss') }"
                format="YYYY-MM-DD HH:mm"
                placeholder="请选择时间"
                v-model="examtime.endtime"
                :open="examtime.endOpen"
                @change="changetime"
                @openChange="handleEndNormalOpenChange($event, examtime)"
              />
              <div style="display: inline-block; margin-left: 50px;">
                <span>学生可使用作答时长：</span>
                <a-input-number :disabled="!isOnlyLook || !timeShow" v-model="examtime.time" :precision="0" :min="0" @change="getExamtime"/>
                <span style="margin-left: 5px;">分钟</span>
                <a-switch :disabled="!isOnlyLook" v-model="timeShow" style="margin-left: 15px;">
                  <a-icon slot="checkedChildren" type="check" />
                  <a-icon slot="unCheckedChildren" type="close" />
                </a-switch>
                <span style="margin-left: 5px;vertical-align: middle;">是否设置学生作答时长</span>
              </div>
            </div>
          </template>
        </div>
        <div v-if="this.typeExam == 1" class="oe-push-left__time">
          <div class="oe-method-left__title">
            <span class="oe-title-circle"></span>
            保存设置
            <a-tooltip placement="bottom" class="oe-push-top__title">
              <template slot="title">
                <span class="oe-title-content">
                  只有当正式考和补考发布的试卷全是客观题考试，才可以保存最高分，
                  <br />否则只能保存最后一次作答纪录。
                </span>
              </template>
              <i class="iconfont icon-wenti"></i>
            </a-tooltip>
          </div>
          <div class="oe-other-item">
            <a-radio-group
              name="radioGroup"
              v-model="saveEdit"
              @change="Changesave"
              :disabled="!isOnlyLook"
            >
              <a-radio :value="1">保存最高分</a-radio>
              <a-radio :value="0">保存最后一次作答纪录</a-radio>
            </a-radio-group>
          </div>

          <!-- <span class="oe-let-time__title">补考考试时间：</span>
          <a-date-picker
            :disabledDate="disabledStartDate"
            showTime
            format="YYYY-MM-DD HH:mm"
            v-model="startValue"
            placeholder="请选择时间"
            @openChange="handleStartOpenChange"
          />
          <span class="oe-let-time__split">--</span>
          <a-date-picker
            :disabledDate="disabledEndDate"
            showTime
            format="YYYY-MM-DD HH:mm"
            placeholder="请选择时间"
            v-model="endValue"
            :open="endOpen"
            @openChange="handleEndOpenChange"
          />-->
        </div>
      </div>
      <div class="oe-push-set clearfix">
        <div class="oe-set-left-box fl">
          <div class="oe-set-time">
            <a-checkbox-group v-model="times">
              <div class="oe-method-left__title">
                <span class="oe-title-circle"></span>
                公布时间
                <span
                  class="iconfont icon-wenti o-exam-tips"
                >归档前该选项支持随时修改（注：归档后将不可修改）</span>
              </div>
              <div class="oe-set-push">
                <span class="oe-set-push__title">作答公开时间：</span>
                <span class="oe-set-push__time">
                  <a-date-picker
                    @change="onPushChange"
                    placeholder="请选择时间"
                    :disabled="times.includes('D')"
                    v-model="AnswerRecordPublishTime"
                    :show-time="{ defaultValue: $moment('00:00:00', 'HH:mm:ss') }"
                    format="YYYY-MM-DD HH:mm"
                  />
                </span>
                <span class="oe-set-push__radio">
                  <a-checkbox value="D">不公布记录</a-checkbox>
                </span>
              </div>
              <div class="oe-set-push">
                <span class="oe-set-push__title">答案公布时间：</span>
                <span class="oe-set-push__time">
                  <a-date-picker
                    @change="onPushChange"
                    placeholder="请选择时间"
                    :disabled="times.includes('A')"
                    v-model="anstime"
                    :show-time="{ defaultValue: $moment('00:00:00', 'HH:mm:ss') }"
                    format="YYYY-MM-DD HH:mm"
                  />
                </span>
                <span class="oe-set-push__radio">
                  <a-checkbox value="A">不公布答案</a-checkbox>
                </span>
              </div>
              <div class="oe-set-push">
                <span class="oe-set-push__title">解析公布时间：</span>
                <span class="oe-set-push__time">
                  <a-date-picker
                    @change="onPushChange"
                    placeholder="请选择时间"
                    :disabled="times.includes('B')"
                    v-model="AnalysisPublishTime"
                    :getCalendarContainer="trigger => trigger.parentNode"
                    :show-time="{ defaultValue: $moment('00:00:00', 'HH:mm:ss') }"
                    format="YYYY-MM-DD HH:mm"
                  />
                </span>
                <span class="oe-set-push__radio">
                  <a-checkbox value="B">不公布解析</a-checkbox>
                </span>
              </div>
              <div class="oe-set-push">
                <span class="oe-set-push__title">成绩公布时间：</span>
                <span class="oe-set-push__time">
                  <a-date-picker
                    @change="onPushChange"
                    placeholder="请选择时间"
                    :disabled="times.includes('C')"
                    v-model="ScorePublishTime"
                    :getCalendarContainer="trigger => trigger.parentNode"
                    :show-time="{ defaultValue: $moment('00:00:00', 'HH:mm:ss') }"
                    format="YYYY-MM-DD HH:mm"
                  />
                </span>
                <span class="oe-set-push__radio">
                  <a-checkbox value="C">不公布成绩</a-checkbox>
                </span>
              </div>
              <div class="oe-set-push">
                <span class="oe-set-push__title">多少天后归档：</span>
                <span class="oe-set-push__time">
                  <a-input-number
                    v-model="stateDay"
                    :min="1"
                    :max="90"
                    :formatter="limitNumber"
                    :parser="limitNumber"
                  />
                  <span
                    class="iconfont icon-wenti o-exam-tips"
                  >归档天数从考试结束后开始算起(最大90天)。归档后，将不能进行批阅，补考，修改信息等。</span>
                </span>
              </div>
            </a-checkbox-group>
          </div>
          <!-- <div class="oe-set-time" style="margin-top: 20px;">
            <a-checkbox-group v-model="times">
              <div class="oe-method-left__title">
                <span class="oe-title-circle"></span>
                人脸识别
              </div>
              <div class="oe-set-push">
                <span class="oe-set-push__title">是否自动人脸识别：</span>
                <span class="oe-set-push__time">
                  <a-radio-group v-model="IsFaceRecognition" @change="onChangeMonitor">
                    <a-radio :value="false">关闭</a-radio>
                    <a-radio :value="true">开启</a-radio>
                  </a-radio-group>
                </span>
              </div>
            </a-checkbox-group>
          </div>-->
        </div>
        <div :class="!isOnline ? 'oe-other-set onlneSetExam' : 'oe-other-set'">
          <div class="oe-method-left__title">
            <span class="oe-title-circle"></span>
            其余设置
          </div>
          <div class="oe-other-set__content">
            <a-checkbox-group @change="onChange" v-model="selection">
              <div class="oe-other-set__item">
                <span class="oe-set-item__title">顺序设置：</span>

                <a-radio-group name="OrderBy" v-model="orderByQuestion" :disabled="!isOnlyLook">
                  <span class="oe-set-item__select">
                    <a-radio :value="0">按题库分类排序</a-radio>
                  </span>
                  <span class="oe-set-item__select margin-reset">
                    <a-radio :value="1">按题型排序</a-radio>
                  </span>
                </a-radio-group>
              </div>
              <div class="oe-other-set__item">
                <span class="oe-set-item__title">乱序设置：</span>
                <span class="oe-set-item__select">
                  <a-checkbox value="QuestionOrderType" :disabled="!isOnlyLook">题目乱序</a-checkbox>
                </span>
                <span class="oe-set-item__select margin-reset">
                  <a-checkbox value="OptionOrderType" :disabled="!isOnlyLook">选项乱序（限单选、多选）</a-checkbox>
                </span>
              </div>
              <div class="oe-other-set__item">
                <span class="oe-set-item__title">显示设置：</span>
                <span class="oe-set-item__select">
                  <a-checkbox value="IsShowQuesType" :disabled="!isOnlyLook">不显示题型</a-checkbox>
                </span>
                <span class="oe-set-item__select margin-reset">
                  <a-checkbox value="IsShowScore" :disabled="!isOnlyLook">不显示试题分数</a-checkbox>
                </span>
              </div>
              <div class="oe-other-set__item" v-if="isOnline">
                <span class="oe-set-item__title">上传设置：</span>
                <span class="oe-set-item__select">
                  <a-checkbox value="UploadType" @click="choose" :disabled="!isOnlyLook">允许学生问答题上传文件</a-checkbox>
                  <small
                    style="margin-left: 29px;color: #f00;margin-bottom: 0;"
                  >(勾选此选项后，关于摄像头和切屏的防作弊设置将不可用)</small>
                </span>
              </div>
              <div class="oe-other-set__item" v-if="isOnline">
                <span class="oe-set-item__title">防作弊设置：</span>
                <span class="oe-set-item__select margin-reset">
                  <a-checkbox value="IsOneOnline" :disabled="!isOnlyLook">唯一设备作答</a-checkbox>
                  <small
                    style="margin-left: 29px;color: #f00;margin-bottom: 0;"
                  >(只允许考生同时在线一个设备进行答题)</small>
                </span>
              </div>
              <div class="oe-other-set__item" v-if="isOnline">
                <span class="oe-set-item__select item-margin">
                  <a-checkbox value="IsProhibitCopy" :disabled="!isOnlyLook">禁止考生复制、粘贴、剪切</a-checkbox>
                </span>
              </div>
              <div class="oe-other-set__item" v-if="isOnline">
                <span class="oe-set-item__select item-margin">
                  <a-checkbox
                    :disabled="!isOnlyLook || isChooseFile"
                    value="checkedCan"
                  >开启摄像，随机抓拍1~
                  <a-input
                  v-if="isCustomPhoto"
                      type="number"
                      :disabled="!selection.includes('checkedCan') || !isOnlyLook || isChooseFile"
                      v-model="photoCount"
                      :min="0"
                      class="oe-split-screen"
                    />
                  <span v-if="!isCustomPhoto">10</span>
                  张照片</a-checkbox>
                  <small v-if="isCustomPhoto"
                    style="margin-left: 29px;color: #f00;margin-bottom: 0;"
                  >(抓拍最大数不能超出考试开始时间与结束时间的分钟差)</small>
                </span>
              </div>
              <div class="oe-other-set__item" v-if="isOnline">
                <span class="oe-set-item__select item-margin" style="display:inline-block;">
                  <a-checkbox value="Changecamera" :disabled="!isOnlyLook || isChooseFile">
                    人脸监测限制考生移出摄像头
                    <a-input
                      type="number"
                      :disabled="!selection.includes('Changecamera') || !isOnlyLook || isChooseFile"
                      v-model="cameracount"
                      :min="-1"
                      class="oe-split-screen"
                    />次，每次扣
                    <a-input
                      type="number"
                      :disabled="!selection.includes('Changecamera') || !isOnlyLook || isChooseFile"
                      v-model="cameraScore"
                      :min="0"
                      class="oe-split-screen"
                    />分，达到次数强制交卷
                  </a-checkbox>
                </span>
              </div>
              <div class="oe-other-set__item" v-if="isOnline">
                <span class="oe-set-item__select item-margin">
                  <a-checkbox value="ChangePaperCount" :disabled="!isOnlyLook || isChooseFile">
                    限制考生切换考试页面
                    <a-input
                      type="number"
                      :disabled="!selection.includes('ChangePaperCount') || !isOnlyLook || isChooseFile"
                      v-model="count"
                      :min="-1"
                      class="oe-split-screen"
                    />次，每次扣
                    <a-input
                      type="number"
                      :disabled="!selection.includes('ChangePaperCount') || !isOnlyLook || isChooseFile"
                      v-model="reduceScore"
                      :min="0"
                      class="oe-split-screen"
                    />分，达到次数强制交卷
                  </a-checkbox>
                  <small>
                    <p
                      style="margin-left: 29px;color: #f00;margin-bottom: 0;"
                    >(以上次数设为 -1 次代表只会记录信息，不会强制提交)</p>
                  </small>
                </span>
              </div>

              <div class="oe-other-set__item" v-if="isOnline">
                <span class="oe-set-item__title">提示设置：</span>
                <span class="oe-set-item__select">
                  <a-checkbox
                    value="isShowCameraCount"
                    :disabled="!isOnlyLook || isChooseFile"
                  >人脸监测,提示剩余多少次交卷</a-checkbox>
                </span>
                <span class="oe-set-item__select margin-reset">
                  <a-checkbox
                    value="isShowPaperCount"
                    :disabled="!isOnlyLook || isChooseFile"
                  >切屏监测,提示剩余多少次交卷</a-checkbox>
                </span>
              </div>
            </a-checkbox-group>
          </div>
        </div>
      </div>
      <div class="oe-exam-link">
        <span class="oe-link-title">考 试 地 点 ：</span>
        <a-input v-model="examAddress" placeholder="请输入考试地点" />
      </div>
      <div class="oe-exam-link" v-if="isOnline">
        <span class="oe-link-title">电 脑 端 链 接：</span>
        <input class="oe-link-inp" v-model="examLink" id="copyInput" readonly="readonly" />
        <!-- <a-input type="text"  readonly="readonly" /> -->
        <span
          ref="copyBtn"
          class="oe-copy-link"
          @mouseover.once="copyLinkAction"
          data-clipboard-target="#copyInput"
          @click.stop="copyLinkAction"
        >复制链接</span>
      </div>
      <div class="oe-exam-link" v-if="isOnline">
        <span class="oe-link-title">手 机 端 链 接：</span>
        <input class="oe-link-inp" v-model="h5ExamLink" id="copyIdMobile" readonly="readonly" />
        <!-- <a-input type="text"  readonly="readonly" /> -->
        <span
          ref="copyMobile"
          class="oe-copy-link"
          @mouseover.once="copyLinkMobile"
          data-clipboard-target="#copyIdMobile"
          @click.stop="copyLinkMobile"
        >复制链接</span>
      </div>
      <div class="oe-exam-link" @click="showModal" v-if="isOnline">
        <span class="oe-link-title reset-indent">手机端二维码：</span>
        <qrcode-vue class="oe-qrcode" :value="h5LoginUrl" :size="size" level="H"></qrcode-vue>
        <a-modal
          :visible="visible"
          :confirm-loading="confirmLoading"
          :footer="null"
          @ok="handleOk"
          @cancel="handleCancel"
          :centered="true"
          width="700px"
        >
          <qrcode-vue class="oe-qrcode" :value="h5LoginUrl" :size="600" level="H"></qrcode-vue>
        </a-modal>
      </div>
      <div class="oe-push-btns" v-if="!stepMode">
        <a-button type="primary" @click="setExam" v-if="operationList.includes('发布考试')">发布考试</a-button>
        <a-button @click="previewPaperAction">预览试卷</a-button>
      </div>
      <div v-else style="display: flex;justify-content: space-around;padding: 50px 30%;background: #fff;">
        <a-button type="primary" @click="$parent.previousStep()">
          上一步
        </a-button>
        <a-button type="primary" @click="watchExam">
          预览试卷
        </a-button>
        <a-button type="primary" @click="setExam"  v-if="operationList.includes('发布考试')">
          发布考试
        </a-button>
        <a-button v-if="isPublic" type="primary" @click="$parent.$refs.back.backAction()">
          返回考试列表
        </a-button>
        <a-button type="primary" @click="$parent.nextStep()" v-if="examMode === 0">
          下一步
        </a-button>
      </div>
    </div>
    <a-modal title="设置题型别名" class="oe-review-modal" centered v-model="visibleQues">
      <div v-for="ques in quesNameList" :key="ques.Id">
        <div class="oe-review-name oe-exam-link" style="width: 95%;">
          {{ques.OldQuestionName}} ->
          <input 
            class="oe-link-inp"
            v-model="ques.QuestionName"
            :disabled="!isOnlyLook"
            :placeholder="ques.QuenNames"
          />
          <a-tooltip placement="bottom" class="oe-push-top__title"  v-if="ques.QuestionTypeMunch == 1">
              <template slot="title">
                <span class="oe-title-info">该类题型的别名不止有一个</span>
                <span class="oe-title-content"><br />{{ques.QuenNames}}</span>
              </template>
              <i class="iconfont icon-wenti"></i>
            </a-tooltip>
        </div>
      </div>
      <div slot="footer">
        <a-button type="primary" @click="setQuesType()" v-if="isOnlyLook && operationList.includes('发布考试')">保存设置</a-button>
        <a-button @click="visibleQues = false">取消</a-button>
      </div>
    </a-modal>
    <a-modal
      v-model="visibleQuesName"
      title="设置题目名称"
      width="926px"
      wrapClassName="oe-modal__manage"
      @cancel="setOffvisibleQuesName"
    >
      <div class="oe-modal-one">
        <span class="oe-question-select">
          <a-select
            v-model="questionType"
            @change="typechange"
            showSearch
            :allowClear="true"
            optionFilterProp="children"
            placeholder="全部题型"
            style="width:160px"
          >
            <a-select-option
              v-for="(item, index) in QuesList"
              :value="item.id"
              :index="index"
              :key="item.id"
            >
              {{
              item.text
              }}
            </a-select-option>
          </a-select>
        </span>
        <span class="oe-question-select">
          <a-select
            v-model="paperStructId"
            @change="typechange"
            showSearch
            :allowClear="true"
            optionFilterProp="children"
            placeholder="全部试卷"
            style="width:160px"
          >
            <a-select-option
              v-for="(item, index) in paperStructList"
              :value="item"
              :index="index"
              :key="item"
            >
              试卷 {{
              item
              }}
            </a-select-option>
          </a-select>
        </span>
        <span class="oe-modal-input">
          <a-input placeholder="题干" v-model="quesTitle" @keyup.13="getWorkQuestion"></a-input>
        </span>
        <a-button class="oe-btn-right" type="primary" @click="getWorkQuestion">查询</a-button>
      </div>
      <div class="oe-modal-table">
        <a-table
          :rowSelection="{ selectedRowKeys: selectedStudent, onChange: onSelectStudent }"
          :columns="modalColumns"
          :dataSource="modalList"
          :pagination="modalPagination"
          :scroll="{ y: 470 }"
          @change="onModalChange"
        />
      </div>
      <template slot="footer">
        <a-button type="primary" @click.stop="setQuesName" v-if="isOnlyLook && operationList.includes('发布考试')">设置题目别名</a-button>
        <a-button class="oe-btn-delete" @click.stop="setOffvisibleQuesName">取消</a-button>
      </template>
    </a-modal>
    <a-modal title="设置题型别名" class="oe-review-modal" centered v-model="QuesSigle">
      <div class="oe-review-name oe-exam-link" style="width: 95%;text-align: center">
        <input class="oe-link-inp" v-model="quesName" placeholder="请输入题目别名" />
      </div>
      <div slot="footer">
        <a-button type="primary" @click="saveSingleName()" v-if="operationList.includes('发布考试')">保存设置</a-button>
        <a-button @click="QuesSigle = false">取消</a-button>
      </div>
    </a-modal>
  </div>
</template>

<script>
import topTip from '@/components/top-tip/index.vue';
import Clipboard from 'clipboard';
import QrcodeVue from 'qrcode.vue';
import moment from 'moment';
import GetOperationList from '@/lib/mixin/methods.js';
export default {
  name: 'pushExam',
  mixins: [GetOperationList],
  components: {
    topTip,
    QrcodeVue
  },
  data() {
    return {
      value: undefined,
      isOnline: '',
      timeShow: false,
      moretime: [
        {
          time: 1,
          endtime: null,
          starttime: null,
          endOpen: false,
          idx: 0,
          name: '轮次1'
        }
      ],
      isCustomPhoto: false,
      QuesSigle: false,
      photoCount: '',
      quesName: '',
      // 分页配置
      modalPagination: {
        pageSizeOptions: ['10', '20', '40', '80', '1000'],
        showSizeChanger: true,
        showTotal(total) {
          return `共 ${total} 条`;
        },
        onShowSizeChange: (current, pageSize) => {
          this.modalPagination.current = current;
          this.modalPagination.pageSize = pageSize;
        },
        onChange: (current, pageSize) => {
          this.modalPagination.current = current;
          this.modalPagination.pageSize = pageSize;
        },
        buildOptionText(props) {
          return props.value + '条/页';
        },
        current: 1,
        pageSize: 10,
        total: 0
      },
      paperStructList: [],
      modalColumns: [
        {
          title: '序号',
          dataIndex: 'number',
          width: '8%',
          key: 'number'
        },
        {
          title: '题干',
          dataIndex: 'Title',
          width: '50%',
          key: 'Title',
          sorter: true
        },
        {
          title: '试卷',
          dataIndex: 'WorkExamStructId',
          width: '12%',
          key: 'WorkExamStructId',
          sorter: true
        },
        {
          title: '题型',
          dataIndex: 'QuestionType',
          width: '15%',
          key: 'QuestionType',
          sorter: true
        },
        {
          title: '别名',
          dataIndex: 'QuestionName',
          width: '15%',
          key: 'QuestionName',
          sorter: true
        }
      ],
      modalSelection() {
        const { modalDefaultKey } = this;
        return {
          selectedRowKeys: modalDefaultKey,
          onChange: this.onModalSelectChange
        };
      },
      QuesList: [
        { id: 1, text: '单选题(客观)' },
        { id: 2, text: '多选题(客观)' },
        { id: 3, text: '判断(客观)' },
        { id: 4, text: '填空题(客观)' },
        { id: 5, text: '填空题(主观)' },
        { id: 6, text: '问答题(主观)' },
        { id: 7, text: '匹配题(客观)' },
        { id: 8, text: '阅读理解(客观)' },
        { id: 9, text: '完形填空(客观)' },
        { id: 11, text: '视听题(客观)' },
        { id: 12, text: '阅读理解(主观)' },
        { id: 13, text: '完形填空(主观)' }
      ],
      idstudents: [],
      modalDefaultKey: [],
      selectedRowKeys: [],
      selectedStudent: [],
      paperStructId: undefined,
      quesTitle: '',
      questionType: undefined,
      modalList: [],
      visibleQuesName: false,
      isOnlyLook: false,
      stateDay: 90,
      examvalue: '',
      visibleQues: false,
      typelist: [],
      maxtime: '',
      visible: false,
      typeExam: 0,
      saveEdit: 1,
      orderByQuestion: 0,
      title: [{ text: '批次(考试)管理' }, { text: '考试管理' }, { text: '发布考试', color: '#1890ff' }],
      radiovalue: '',
      cameracount: '',
      cameraScore: '',
      loading: false,
      selection: [],
      times: [],
      quesNameList: [],
      // 设置登录方法
      loginMethod: '',
      ruleForm: {
        beforeLogin: '',
        delayLogin: '',
        commit: ''
      },
      rules: {
        beforeLogin: [{ required: true, trigger: 'change' }],
        delayLogin: [{ required: true, trigger: 'change' }],
        commit: [{ required: true, trigger: 'change' }]
      },
      // 补考考试参数
      // startValue: null,
      // endValue: null,
      // endOpen: false,
      // 正式考试时间参数
      anstime: null,
      AnalysisPublishTime: null,
      ScorePublishTime: null,
      AnswerRecordPublishTime: null,
      startNormalValue: null,
      endNormalValue: null,
      endNormalOpen: false,
      // 发布时间的选择
      pushTimeRadio: null,
      // 答案公布时间：
      answerPushTime: null,
      // 切换考试的次数
      count: '',
      // 每次扣积分
      reduceScore: '',
      // 考试链接
      examLink: '',
      h5ExamLink: '',
      h5LoginUrl: '',
      examAddress: '',
      examLogin: '',
      IsShowQuesType: '',
      isAnalysisPublish: '',
      isFixedPublish: '',
      isScorePublish: '',
      isAnswerRecordPublish: '',
      questionOrderType: '',
      optionOrderType: '',
      isShowQues: '',
      isShowScore: '',
      isProhibitCopy: '',
      IsOneOnline: '',
      IsAllowMark: false,
      isShowCameraCount: '',
      isShowPaperCount: '',
      isChange: false,
      // size: 90,
      // code: '0123456789',
      // char: '',
      // result: '',
      idx: 0,
      cacheItem: '',
      UsePaper: '',
      IsCanAdd: true,
      IsFaceRecognition: false,
      checkedCan: '',
      isChooseFile: false,
      batchTitle:'',
      examTitle:'',
       operationList: []
    };
  },
  props:{
    batchid: {
      type: String,
      default: ''
    },
    stepMode:{
      type:Boolean,
      default:false
    },
    isPublic:{
      type:Boolean,
      default:false
    },
    isHasBK:{
      type:Boolean,
      default:false
    },
    examid: {
      type: String,
      default: ''
    },
    examMode: {
      type: Number,
      default: 0
    }
  },
  watch: {
    pushTimeRadio(newVal) {
      console.log('newVal', newVal);
    },
    timeShow(e) {
      if (e) {
        if (this.moretime[0].time == -1 || this.moretime[0].time == undefined) {
          this.moretime[0].time = 0;
        }
      } else {
        this.moretime[0].time = undefined;
      }
    }
  },
  mounted(){
    this.getOpeartion()
    this.getSetExamInfo()
  },
  methods: {
    setBoolean(e) {
      return e
    },
    watchExam(){
      let newPage = this.$router.resolve({
        name: 'reviewPaper',
        params: {
          batchid: this.batchid,
          examid: this.examid
        }
      });
      window.open(newPage.href, '_blank');
    },
    onChangeMonitor() {
      console.log(this.IsFaceRecognition);
    },
    onChangeCheck(e) {
      //console.log(`checked = ${e.target.checked}`);
      var aa = `checked = ${e.target.checked}`;
      if (aa == 'checked = true') {
        this.checkedCan = true;
      } else {
        this.checkedCan = false;
      }
    },
    limitNumber(value) {
      if (typeof value === 'string') {
        return !isNaN(Number(value)) ? value.replace(/^(0+)|[^\d]/g, '') : '';
      } else if (typeof value === 'number') {
        return !isNaN(value) ? String(value).replace(/^(0+)|[^\d]/g, '') : '';
      } else {
        return '';
      }
    },
    addtimes() {
      if (this.moretime[this.idx].endtime != null && this.moretime[this.idx].starttime != null) {
        this.moretime.push({
          endtime: null,
          starttime: null,
          endOpen: false,
          idx: (this.idx += 1)
          // name: '轮次' + (this.idx + 1)
        });
      } else {
        this.$message.warn('请将前一个时间点选择完成');
      }
    },
    deletetime(index) {
      if (this.moretime.length > 1) {
        this.moretime.splice(index, 1);
        this.idx -= 1
      } else {
        this.$message.warn('至少需要一个考试时间');
      }
    },
    showModal() {
      this.visible = true;
    },
    handleCancel() {
      this.visible = false;
    },
    changetime() {
      this.maxtime = moment(this.moretime[0].endtime).diff(moment(this.moretime[0].starttime), 'minute');
    },
    // refreshCode() {
    //   this.code = '0123456789';
    //   this.result = '';
    //   for (var i = 0; i < 8; i++) {
    //     var code_index = Math.round(Math.random() * 9);
    //     this.char = this.code[code_index];
    //     if (this.result.toUpperCase().indexOf(this.char.toUpperCase()) > -1) {
    //       i--;
    //       continue; //终止本轮循环 进行下一轮
    //     }

    //     this.result += this.char;
    //     // console.log(this.result);
    //   }
    //   this.examLogin = this.result;
    // },
    handleChange() {
      this.isChange = true;
    },
    onChange(checkedValues) {
      if (!this.selection.includes('ChangePaperCount')) {
        this.count = '';
      }
      if (!this.selection.includes('Changecamera')) {
        this.cameracount = '';
      }
      if (!this.selection.includes('checkedCan')) {
        this.photoCount = '';
      }
    },
    Changetype() {
      this.typelist = [];
      this.isChange = true;
      this.moretime = [
        {
          time: 0,
          endtime: null,
          starttime: null,
          endOpen: false,
          idx: 0,
          name: '轮次1'
        }
      ];
      this.isOnlyLook = false;
      this.isChooseFile = false;
      this.isOnline = '';
      this.radiovalue = '';
      this.loginMethod = '';
      this.examLogin = '';
      this.ruleForm.beforeLogin = null;
      this.ruleForm.delayLogin = null;
      this.ruleForm.commit = null;
      this.saveEdit = '';
      this.orderByQuestion = '';
      this.startNormalValue = null; //开始考试时间
      this.endNormalValue = null; //结束考试时间
      this.reduceScore = ''; //切屏分数
      this.cameraScore = '';
      this.selection = [];
      this.examLink = '';
      this.h5ExamLink = '';
      this.h5LoginUrl = '';
      this.times = [];
      this.examAddress = '';
      this.getSetExamInfo(this.typeExam);
    },
    getSetExamInfo() {
      this.loading = true;

      this.$http
        .post('/api/design/workexam/getSetExamInfo', {
          examId: this.examid,
          examType: this.typeExam
        })
        .then((res) => {
          this.loading = false;
          if (res.code === 1) {
            this.typelist = res.paperList;
            if (res.paperList.length > 0) {
              if (res.exam.UsePaper === 0) {
                this.examvalue = '0';
              } else {
                this.examvalue = '1';
              }
            } else {
              this.examvalue = '';
            }

            if (res.timeList.length > 0) {
              this.moretime = [];
              if (res.exam.StuCanUseTime == -1) {
                this.timeShow = false;
                res.exam.StuCanUseTime = undefined;
              } else {
                this.timeShow = true
              };
              res.timeList.forEach((item, index) => {
                this.moretime.push({
                  time: res.exam.StuCanUseTime,
                  endtime: item.EndTime ? this.$moment(item.EndTime, 'YYYY-MM-DD HH:mm:ss') : "",
                  starttime: item.StartTime ? this.$moment(item.StartTime, 'YYYY-MM-DD HH:mm:ss') : "",
                  endOpen: false,
                  idx: index
                });
              });
            } else {
              this.moretime;
            }
            //this.checkedCan = res.exam.IsRandomPhoto;
            console.log(this.checkedCan);
            this.isCustomPhoto = res.isCustomPhoto;
            this.stateDay = res.stateDay;
            this.IsCanAdd = res.exam.ExamMode == 1 ? true : false;
            this.isOnlyLook = res.isCanDoTime;
            this.isOnline = res.isOnline;
            this.radiovalue = res.exam.LoginType;
            this.loginMethod = res.exam.LoginType;
            this.examLogin = res.num;
            this.ruleForm.beforeLogin = res.exam.AdvanceTime;
            this.ruleForm.delayLogin = res.exam.ExtendTime;
            this.ruleForm.commit = res.exam.AllowTime;
            this.saveEdit = res.exam.SaveType;
            this.IsFaceRecognition = res.exam.IsFaceRecognition;
            this.orderByQuestion = res.exam.OrderByQuestion;
            this.startNormalValue = res.exam.StartTime ? this.$moment(res.exam.StartTime, 'YYYY-MM-DD HH:mm:ss') : null; //开始考试时间
            this.endNormalValue = res.exam.EndTime ? this.$moment(res.exam.EndTime, 'YYYY-MM-DD HH:mm:ss') : null; //结束考试时间
            // this.startValue = res.exam.RepairStartDate
            //   ? this.$moment(res.exam.RepairStartDate, 'YYYY-MM-DD HH:mm:ss')
            //   : null; //补考开始时间
            // this.endValue = res.exam.RepairEndDate ? this.$moment(res.exam.RepairEndDate, 'YYYY-MM-DD HH:mm:ss') : null; //补考结束时间
            this.reduceScore = res.exam.BuckleScore; //切屏分数
            this.cameraScore = res.exam.CameraBuckleScore;
            this.selection = [];
            this.examLink = res.url;
            this.h5ExamLink = res.h5Url;
            this.h5LoginUrl = res.h5LoginUrl;
            this.times = [];
            this.maxtime = moment(this.endNormalValue).diff(moment(this.startNormalValue), 'minute');
            console.log('this.maxtime', this.maxtime);
            this.examAddress = res.address;
            if (res.exam.FixedPublishTime == '') {
              this.times.push('A');
              this.anstime = null;
            } else {
              this.anstime = this.$moment(res.exam.FixedPublishTime, 'YYYY-MM-DD HH:mm:ss');
            }
            if (res.exam.AnalysisPublishTime == '') {
              this.times.push('B');
              this.AnalysisPublishTime = null;
            } else {
              this.AnalysisPublishTime = this.$moment(res.exam.AnalysisPublishTime, 'YYYY-MM-DD HH:mm:ss');
            }
            if (res.exam.ScorePublishTime == '') {
              this.times.push('C');
              this.ScorePublishTime = null;
            } else {
              this.ScorePublishTime = this.$moment(res.exam.ScorePublishTime, 'YYYY-MM-DD HH:mm:ss');
            }
            if (res.exam.AnswerRecordPublishTime == '') {
              this.times.push('D');
              this.AnswerRecordPublishTime = null;
            } else {
              this.AnswerRecordPublishTime = this.$moment(res.exam.AnswerRecordPublishTime, 'YYYY-MM-DD HH:mm:ss');
            }
            if (res.exam.QuestionOrderType === 1) {
              this.selection.push('QuestionOrderType');
            }
            if (res.exam.OptionOrderType === 1) {
              this.selection.push('OptionOrderType');
            }
            if (res.exam.IsShowQuesType === false) {
              this.selection.push('IsShowQuesType');
            }
            if (res.exam.IsShowCameraCount === true) {
              this.selection.push('isShowCameraCount');
            }
            if (res.exam.IsShowPaperCount === true) {
              this.selection.push('isShowPaperCount');
            }
            if (res.exam.IsShowScore === false) {
              this.selection.push('IsShowScore');
            }
            if (res.exam.UploadType === 1) {
              this.selection.push('UploadType');
              this.isChooseFile = true;
            }
            if (res.exam.IsProhibitCopy === true) {
              this.selection.push('IsProhibitCopy');
            }
            if (res.exam.IsOneOnline === true) {
              this.selection.push('IsOneOnline');
            }
            this.IsAllowMark = res.exam.IsAllowMark;
            if (res.exam.IsRandomPhoto === true) {
              this.photoCount = res.exam.PhotoCount;
              this.selection.push('checkedCan');
            }
            if (res.exam.ChangePaperCount != -1) {
              if (res.exam.ChangePaperCount == -2) {
                res.exam.ChangePaperCount = -1;
              }
              this.selection.push('ChangePaperCount');
              this.count = res.exam.ChangePaperCount ? res.exam.ChangePaperCount : ''; //切屏次数
            } else {
              this.count = '';
            }
            if (res.exam.CameraChangeCount != -1) {
              if (res.exam.CameraChangeCount == -2) {
                res.exam.CameraChangeCount = -1;
              }
              this.selection.push('Changecamera');
              this.cameracount = res.exam.CameraChangeCount ? res.exam.CameraChangeCount : '';
            } else {
              this.cameracount = '';
            }
          } else {
            this.$message.error(res.msg);
            !this.stepMode && this.$router.back();
          }
        });
    },
    choose() {
      this.isChooseFile = this.selection.includes('UploadType') ? false : true;
    },
    setExam() {
      this.loading = true;
      let UsePaper = '';
      if (
        (this.times.includes('A') == false && this.anstime == null) ||
        (this.times.includes('B') == false && this.AnalysisPublishTime == null) ||
        (this.times.includes('C') == false && this.ScorePublishTime == null) ||
        (this.times.includes('D') == false && this.AnswerRecordPublishTime == null)
      ) {
        this.$message.error('公布时间不能为空');
        this.loading = false;
      } else {
        if (this.examvalue === 0 || this.examvalue === 'A卷') {
          this.UsePaper = 0;
        } else {
          this.UsePaper = 1;
        }
        var timeselect = [];
        var stuCanUseTime = this.moretime[0].time;
        if (stuCanUseTime == undefined) {
          stuCanUseTime = -1;
        };
        for (let i = 0; i < this.moretime.length; i++) {
          // console.log(this.moretime[i].starttime, 'this.moretime[i].starttime');
          if (this.moretime[i].starttime == null && this.moretime[i].endtime == null) {
            timeselect = [];
          } else {
            timeselect.push(
              this.$moment(this.moretime[i].starttime).format('YYYY-MM-DD HH:mm:ss') +
                ';' +
                this.$moment(this.moretime[i].endtime).format('YYYY-MM-DD HH:mm:ss')
            );
          }
        }
        var realCount = 0;
        if (this.count == -1) {
          realCount = -2;
        } else {
          realCount = this.count ? this.count : -1;
        }
        if (this.examMode === 0) {
          if (this.selection.includes('Changecamera') && (!this.cameracount || this.cameracount == '' || this.cameracount < 1) && this.cameracount != -1) {
            this.$message.error('请输入正确的考生移除摄像头次数');
            this.loading = false;
            return false;
          }
          if (this.selection.includes('ChangePaperCount') && (!this.count || this.count == '' || this.count < 1) && this.count != -1) {
            this.$message.error('请输入正确的考生切换页面次数');
            this.loading = false;
            return false;
          }
        }
        var realCameracount = 0;
        if (this.cameracount == -1) {
          realCameracount = -2;
        } else {
          realCameracount = this.cameracount ? this.cameracount : -1;
        }
        this.$http
          .post('/api/design/workexam/setExam', {
            examId: this.examid,
            loginType: this.loginMethod,
            loginCode: this.examLogin,
            advanceTime: this.ruleForm.beforeLogin,
            extendTime: this.ruleForm.delayLogin,
            allowTime: this.ruleForm.commit,
            times: timeselect,
            isFaceRecognition: this.IsFaceRecognition,
            // startDate: this.$moment(this.startNormalValue).format('YYYY-MM-DD HH:mm:ss'),
            // endDate: this.$moment(this.endNormalValue).format('YYYY-MM-DD HH:mm:ss'),
            fixedPublishTime: this.times.includes('A')
              ? null
              : this.$moment(this.anstime).format('YYYY-MM-DD HH:mm:ss'),
            isFixedPublish: this.times.includes('A') ? false : true,
            analysisPublishTime: this.times.includes('B')
              ? null
              : this.$moment(this.AnalysisPublishTime).format('YYYY-MM-DD HH:mm:ss'),
            isAnalysisPublish: this.times.includes('B') ? false : true,
            scorePublishTime: this.times.includes('C')
              ? null
              : this.$moment(this.ScorePublishTime).format('YYYY-MM-DD HH:mm:ss'),
            isScorePublish: this.times.includes('C') ? false : true,
            answerRecordPublishTime: this.times.includes('D')
              ? null
              : this.$moment(this.AnswerRecordPublishTime).format('YYYY-MM-DD HH:mm:ss'),
            isAnswerRecordPublish: this.times.includes('D') ? false : true,
            // repairStartDate: this.startValue ? this.$moment(this.startValue).format('YYYY-MM-DD HH:mm:ss') : '',
            // repairEndDate: this.endValue ? this.$moment(this.endValue).format('YYYY-MM-DD HH:mm:ss') : '',
            questionOrderType: this.selection.includes('QuestionOrderType') ? 1 : 2,
            optionOrderType: this.selection.includes('OptionOrderType') ? 1 : 2,
            uploadType: this.selection.includes('UploadType') ? 1 : 0,
            isShowQues: this.selection.includes('IsShowQuesType') ? false : true,
            isShowScore: this.selection.includes('IsShowScore') ? false : true,
            isProhibitCopy: this.selection.includes('IsProhibitCopy') ? true : false,
            isOneOnline: this.selection.includes('IsOneOnline') ? true : false,
            isAllowMark: this.IsAllowMark,
            changePaperCount: realCount,
            buckleScore: this.reduceScore,
            cameraChangeCount: realCameracount,
            //isRandomPhoto: this.checkedCan,
            isRandomPhoto: this.selection.includes('checkedCan') ? true : false,
            cameraBuckleScore: this.cameraScore,
            address: this.examAddress,
            saveType: this.saveEdit,
            orderByQuestion: this.orderByQuestion,
            examType: this.typeExam,
            paperType: this.examvalue,
            isShowCameraCount: this.selection.includes('isShowCameraCount') ? true : false,
            isShowPaperCount: this.selection.includes('isShowPaperCount') ? true : false,
            quesJson: JSON.stringify(this.quesNameList),
            stateDay: this.stateDay,
            photoCount:this.photoCount,
            stuCanUseTime: stuCanUseTime //学生可使用作答时长
          })
          .then((res) => {
            this.loading = false;
            if (res.code === 1) {
              this.$message.success(res.msg);
              if(this.stepMode){
                this.$parent.getExamStatus(2)
              }else{
                this.$router.back();
              }
            } else {
              this.$message.error(res.msg);
            }
          });
      }
    },
    getExamtime() {
      if (this.selection.includes('checkedCan')) {
        if (this.photoCount) {
          if (this.photoCount > this.moretime[0].time) {
            this.moretime[0].time = this.photoCount;
            this.$message.error('学生作答时长不可小于抓拍次数');
          }
        }
      }
    },
    getQuestionNames() {
      this.loading = true;
      this.$http
        .post('/api/design/workexam/getExamQuesName', {
          examId: this.examid,
          paperType: this.examvalue
        })
        .then((res) => {
          this.isChange = false;
          this.loading = false;
          this.visibleQues = true;
          this.loading = false;
          this.quesNameList = res.list;
        });
    },
    setQuesType() {
      this.loading = true;
      this.$http
        .post('/api/design/workexam/saveQuesTionName', {
          examId: this.examid,
          paperType: this.examvalue,
          examType: this.typeExam,
          quesJson: JSON.stringify(this.quesNameList)
        })
        .then((rst) => {
          this.loading = false;
          if (rst.code === 1) {
            this.visibleQues = false;
            this.$message.success(rst.msg);
          } else {
            this.$message.error(rst.msg);
          }
        });
    },
    getCode() {
      this.$http.post('/api/design/workexam/getCode', {}).then((res) => {
        this.examLogin = res.num;
      });
    },
    //登录复制
    copyLoginAction() {
      const clipboard = new Clipboard(this.$refs.copylg);
      clipboard.on('success', (e) => {
        this.$message.success('复制成功');
        e.clearSelection(); // 清除选中内容
        clipboard.destroy();
      });
      clipboard.on('error', (e) => {
        this.$message.error('复制失败，请采用手动复制');
        clipboard.destroy();
      });
    },
    // 点击复制PC链接操作
    copyLinkAction() {
      const clipboard = new Clipboard(this.$refs.copyBtn);
      // 复制成功后执行的回调函数
      clipboard.on('success', (e) => {
        this.$message.success('复制成功');
        e.clearSelection(); // 清除选中内容
        clipboard.destroy();
      });
      clipboard.on('error', (e) => {
        this.$message.error('复制失败，请采用手动复制');
        clipboard.destroy();
      });
    },
    // 点击复制Mobile链接操作
    copyLinkMobile() {
      const clipboard = new Clipboard(this.$refs.copyMobile);
      // 复制成功后执行的回调函数
      clipboard.on('success', (e) => {
        this.$message.success('复制成功');
        e.clearSelection(); // 清除选中内容
        clipboard.destroy();
      });
      clipboard.on('error', (e) => {
        this.$message.error('复制失败，请采用手动复制');
        clipboard.destroy();
      });
    },
    onLoginMethod(val) {
      this.radiovalue = val;
    },
    disabledNormalStartDate(startNormalValue) {
      let index = this.moretime.findIndex((item) => {
        return item.idx === this.cacheItem.idx;
      });
      if (index > -1) {
        if (this.cacheItem.idx) {
          const otherendTime = this.moretime[index - 1].endtime;
          if (!startNormalValue || !otherendTime) {
            return false;
          }
          return startNormalValue.valueOf() <= this.moretime[index - 1].endtime.valueOf();
        } else {
          const endNormalValue = this.moretime[index].endtime;
          if (!startNormalValue || !endNormalValue) {
            return false;
          }
          return startNormalValue.valueOf() >= endNormalValue.valueOf();
        }
      }
    },
    disabledNormalEndDate(endNormalValue) {
      let index = this.moretime.findIndex((item) => {
        return item.idx === this.cacheItem.idx;
      });
      if (index > -1) {
        const startNormalValue = this.moretime[index].starttime;
        if (!endNormalValue || !startNormalValue) {
          return false;
        }
        return startNormalValue.valueOf() >= endNormalValue.valueOf();
      }
    },
    handleStartNormalOpenChange(open, data) {
      this.cacheItem = data;
      if (!open) {
        let index = this.moretime.findIndex((item) => {
          return item.idx === data.idx;
        });
        if (index > -1) {
          this.moretime[index].endOpen = true;
        }
        if (!this.moretime[0].endtime && this.moretime[0].starttime) {
          let date = this.$moment(Number(this.moretime[0].starttime)+1000*60);
          console.log(typeof(date));
          this.moretime[0].endtime = this.$moment(Number(this.moretime[0].starttime)+1000*60);
          
        }
      }
    },
    handleEndNormalOpenChange(open, data) {
      let index = this.moretime.findIndex((item) => {
        return item.idx === data.idx;
      });
      if (index > -1) {
        this.moretime[index].endOpen = open;
      };
    },
    // 公布答案时间
    onPushChange(val) {},
    // 预览试卷
    previewPaperAction() {
      this.$router.push({
        name: 'reviewPaper',
        params: {
          batchid: this.batchid,
          examid: this.examid
        }
      });
    },
    // 点击table排序
    onModalChange(pagenation, filter, sort) {
      let sortOrder = '';
      if (sort.order) {
        if (sort.order == 'ascend') {
          sortOrder = sort.columnKey;
        } else if (sort.order == 'descend') {
          sortOrder = '-' + sort.columnKey;
        } else {
          sortOrder = '';
        }
      }
      this.getWorkQuestion(pagenation.current, pagenation.pageSize, sortOrder);
    },
    // 获取modal选择的
    onModalSelectChange(selectedRowKeys, selectedRow) {
      this.modalDefaultKey = selectedRowKeys;
      this.modalRowSelect = selectedRow;
    },
    onSelectStudent(selectedRowKeys, selectedRows) {
      this.selectedStudent = selectedRowKeys;
      var ids = [];
      for (let i = 0; i < selectedRows.length; i++) {
        ids.push(selectedRows[i].Id);
      }
      this.idstudents = ids;
    },
    getOpeartion() {
      this.loading = true;
      this.GetOperationList('examId',this.examid).then((rst) => {
        this.loading = false;
        if (rst.code === 1) {
          if (rst.list.length) {
            rst.list.forEach((item) => {
              if (item.IsWrite) {
              this.operationList.push(item.Name);
              }
            });
          }
          this.examTitle = rst.examTitle
          this.batchTitle = rst.batchTitle
        } else {
          this.$message.error(rst.msg);
        }
      });
    },
    getWorkQuestion(current, pageSize, sort, type) {
      this.loading = true;
      this.$http
        .post('/api/design/workexam/getExamQuesList', {
          examId: this.examid,
          paperType: this.examvalue,
          title: this.quesTitle || '',
          questionType: this.questionType,
          sort,
          pageSize: pageSize || 10,
          page: current || 1,
          paperStructId: this.paperStructId,
          examType:this.typeExam
        })
        .then((rst) => {
          this.loading = false;
          if (rst.code === 1) {
            this.paperStructList = rst.paperStructList;
            this.visibleQuesName = true;
            this.modalList = [];
            this.modalPagination.current = rst.pagination.pageIndex;
            this.modalPagination.pageSize = rst.pagination.pageSize;
            this.modalPagination.total = rst.pagination.totalCount;
            if (rst.list.length) {
              rst.list.forEach((item, index) => {
                let number = (rst.pagination.pageIndex - 1) * rst.pagination.pageSize + index + 1;
                let key = (rst.pagination.pageIndex - 1) * rst.pagination.pageSize + index;
                this.modalList.push({
                  ...item,
                  key: item.Id,
                  number: number
                });
              });
            }
            if (type) {
              let index = this.schoolList.findIndex((item) => {
                return item.id === rst.schoolId;
              });
              if (index > -1) {
                this.school = this.schoolList[index].id;
              }
              // this.getFactoryList('', rst.schoolId);
            }
          } else {
            this.$message.error(rst.msg);
          }
        });
    },
    setOffvisibleQuesName() {
      this.visibleQuesName = false;
      this.paperStructId = undefined;
      this.questionType = undefined;
      this.quesTitle = '';
    },
    setQuesName() {
      if (this.idstudents.length == 0) {
        this.$message.error('请选择要设置的题目');
        return;
      }
      this.QuesSigle = true;
    },
    saveSingleName() {
      this.loading = true;
      this.$http
        .post('/api/design/workexam/saveNameForQues', {
          examId: this.examid,
          paperType: this.examvalue,
          examType: this.typeExam,
          ids: this.idstudents,
          quesName: this.quesName
        })
        .then((rst) => {
          this.loading = false;
          if (rst.code === 1) {
            this.QuesSigle = false;
            this.idstudents = [];
            this.selectedStudent = [];
            this.quesName = '';
            this.getWorkQuestion();
            this.$message.success(rst.msg);
          } else {
            this.$message.error(rst.msg);
          }
        });
    }
  }
};
</script>
